<{include file="admin/header.html"}>
<div class="container">
	<div class="floattop">
		<div class="itemtitle">
			<h3>产品类别管理</h3>
			<ul class="tab1">
				<li><a href="product_cate_manage.php"><span>类别列表</span></a></li>
				<li><a href="?act=show_add_form"><span>添加类别</span></a></li>
			</ul>
		</div>
	</div>
	<div class="floattopempty"></div>

	<{if $show_add_form}>
		<form id="formadd" action="?act=add" method="post">
			<table class="tb tb2">
				<tbody>
					<tr>
						<td class="td27" colspan="2">类别名称：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="text" value="" name="cate_name">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td colspan="15">
							<input class="btn" type="submit" value="提交">
						</td>
					</tr>
				</tbody>
			</table>
		</form>
	<{elseif $show_edit_form}>
		<form id="formedit" action="?act=save" method="post">
			<table class="tb tb2">
				<tbody>
					<tr>
						<td class="td27" colspan="2">类别名称：</td>
					</tr>
					<tr class="noborder">
						<td class="vtop rowform">
							<input class="txt" type="text" value="<{$categorys.cate_name}>" name="cate_name">
						</td>
						<td class="vtop tips2"></td>
					</tr>
					<tr>
						<td colspan="15">
							<input class="btn" type="submit" value="保存">
						</td>
					</tr>
				</tbody>
			</table>
			<input type="hidden" name="cate_id" value="<{$categorys.cate_id}>">
			<input type="hidden" name="o_cate_name" id="o_cate_name" value="<{$categorys.cate_name}>">
		</form>		
	<{else}>
		<div class="list-div">
		<table class="tb tb2" cellspacing="1" cellpadding="3">
			<tbody>
				<tr class="header">
					<th>编号</th>
					<th>类别名称</th>
					<th>操作</th>
				</tr>
				<{foreach from=$cate_list item=cl}>
				<tr class="td-cls">
					<td><{$cl.cate_id}></td>
					<td><{$cl.cate_name}></td>
					<td><span class="operation"><a href="?act=edit&cate_id=<{$cl.cate_id}>">编辑</a></span><span class="operation"><a href="#" class="del">删除</a></span></td>
				</tr>
				<{/foreach}>	
			</tbody>
		</table>
		</div>	
	<{/if}>
</div>
<script type="text/javascript">
$(document).ready(function(){
	$('#formadd, #formedit').validate({
		rules: {
			cate_name: {
				required: true,
				remote: {
					url:'product_cate_manage.php',
					data: {
						act:'checkExist',
						o_cate_name:function(){return $("#o_cate_name").val()}
					}
				}
			}
		},
		messages: {
			cate_name: {required: '请输入类别名称',remote:'类别名称已存在'}
		},
		success:function(label) { 
			label.html(" ").addClass("right");
		}
		
	});
});

$(".del").click(function(){
	if(confirm('确认删除？')) {
		var obj = $(this);
		var $cate_id = obj.parents('tr').find('td').eq(0).text();
		$.get('product_cate_manage.php', {act:'del', cate_id:$cate_id}, function(data){ 
			if(data == 1) {
				alert('删除成功');
				obj.parents('tr').remove();	
			}
			if(data == 0) {
				alert('此类别下存在数据，不能删除！');
			}
		});
	}
});

</script>
<{include file="admin/footer.html"}>

